<template>
  <div class="statistics">
    <div class="box-left">
      <work-tree @workSelected="workSelectedHandler"/>
    </div>
    <div class="box-right">
      <!--工作总览-->
      <!--上报管理-当前用户-->
      <reporting-active-user :dataList="regionData" v-if="departInfo.areaLevel != 1"/>
      <reporting-active-province-user :dataList="provinceInfo" v-if="departInfo.areaLevel == 1"/>
      <reporting-province-sub-user :data="nextRegionData" :workId="models.workId" v-if="departInfo.areaLevel === 1"/>
      <!--上报管理-下级用户-->
      <reporting-sub-user :data="nextRegionData" :workId="models.workId" v-if="departInfo.areaLevel === 2"/>
      <reporting-county-user :data="countyRegionData" :workId="models.workId" v-if="departInfo.areaLevel === 1"/>
      <!--统计表-->
    </div>
  </div>
</template>

<script lang="ts">
import {Component, Vue} from 'vue-property-decorator';
import WorkTree from "@/views/region/components/WorkTree.vue";
import ReportingActiveUser from "@/views/region/components/ReportingActiveUser.vue";
import ReportingActiveProvinceUser from "@/views/region/components/ReportingActiveProvinceUser.vue";
import ReportingSubUser from "@/views/region/components/ReportingSubUser.vue";
import ReportingCountyUser from "@/views/region/components/ReportingCountyUser.vue";
import ReportingProvinceSubUser from "@/views/region/components/ReportingProvinceSubUser.vue";
import {getAreaConfirm,getNextAreaConfirm,getCountyAreaConfirm} from '@/api/areaConfirm'
import {Getter} from 'vuex-class';
@Component({
  components: {WorkTree, ReportingActiveUser,ReportingProvinceSubUser,ReportingCountyUser,ReportingActiveProvinceUser,ReportingSubUser}
})
export default class ReportManager extends Vue {
  @Getter('departInfo') private departInfo!: any;
  regionData:any=[];
  provinceInfo:any=[];
  nextRegionData:any=[];
  countyRegionData:any=[];

  private models:any ={
    position:'',
    vectorId:'',
    workId:''
  };

  workSelectedHandler(workId){
    this.models.workId = workId;
    this.getThisAreaConfirm(workId);
  }


  getThisAreaConfirm(workId){
    getAreaConfirm({workId:workId}).then(res =>{
        if(!res.data){
          this.$message.error("本级无任务");
          this.regionData =[];
          return;
        }
        this.regionData = [res.data.areaConfirm];
        if(res.data.provinceInfo){
          this.provinceInfo = [res.data.provinceInfo];
        }
        this.$store.dispatch('saveAreaData',res.data.areaConfirm)
      }).catch(e =>{
        console.error(e);
      });

        getNextAreaConfirm({workId:workId}).then(res =>{
          if(!res.data){
              this.$message.error("下级无任务");
              this.nextRegionData =[];
              return;
          }
          this.nextRegionData = res.data;
      }).catch(e =>{
        console.error(e);
      });
      if(this.departInfo.areaLevel === 1){
        getCountyAreaConfirm({workId:workId}).then(res =>{
          if(!res.data){
              this.$message.error("下级无任务");
              this.countyRegionData =[];
              return;
          }
          this.countyRegionData = res.data;
      }).catch(e =>{
        console.error(e);
      });
      }


  }
  mounted(){
    (this as any).$bus.$on('taskChangedHandler',(workId:number) =>{
        this.getThisAreaConfirm(workId);
    });
  }
}
</script>
<style lang="scss" scoped>
.statistics {
  display: flex;
  gap: 16px;
  .box-left{
    height: auto;
  }
  .box-right {
    margin-top: 10px;
    flex: 1;
    padding: 0px;
    display: flex;
    flex-direction: column;
    gap: 16px;
  }
}
</style>
